#include "persistence_com.h"







int main(void)
{
    printf("test-------->\r\n");
<<<<<<< HEAD
    persistence_handle_t *handle = persistence_com_init(10, "./persist.bak", PERSIST_MODE_FILE);
    if(handle)
    {
        for(int i = 0; i < 15; i++)
        {
           char buf[30] = {0};
           snprintf(buf, 30, "%d", i);
           int ret = persistence_com_push(handle, buf, strlen(buf), i);
           printf("---> read index %d write index %d %s\r\n", handle->header.read_index, handle->header.write_index, buf);
           if(ret == -2)
           {
              persistence_com_pop(handle);
              ret = persistence_com_push(handle, buf, strlen(buf), i);
              printf("---> read index %d write index %d %s\r\n", handle->header.read_index, handle->header.write_index, buf);
           }
        }
    }
=======
    persistence_handle_t *handle = persistence_com_init(1000, "./persist.bak", PERSIST_MODE_FILE);
    persistence_dump(handle, PERSIST_DUMP_HEADER);
    // if(handle)
    // {
    //     for(int i = 0; i < 15; i++)
    //     {
    //        char buf[30] = {0};
    //        snprintf(buf, 30, "%d", i);
    //        int ret = persistence_com_push(handle, buf, strlen(buf), i);
    //        printf("---> read index %d write index %d %s\r\n", handle->header.read_index, handle->header.write_index, buf);
    //        if(ret == -2)
    //        {
    //           persistence_com_pop(handle);
    //           ret = persistence_com_push(handle, buf, strlen(buf), i);
    //           printf("---> read index %d write index %d %s\r\n", handle->header.read_index, handle->header.write_index, buf);
    //        }
    //     }
    // }
>>>>>>> fce35a03da8b8eb1530708c7cf62c40c49150153
    printf("test----------->\r\n");
    usr_data_t unit = {0};
    while(1)
    {
        memset(&unit, 0, sizeof(usr_data_t));
        if(persistence_com_get(handle, &unit) == 0)
        {
            printf("---> read index %d write index %d data: %s id: %d\r\n", handle->header.read_index, handle->header.write_index, unit.data, unit.id);
            persistence_com_pop(handle);
        }
        else
        {
            printf("-------> get data fail \r\n");
            break;
        }
    }
    printf("persist deinit \r\n");
    persistence_com_deinit(handle);
    return 0;
}